#include "utils.h"

double convert_time(struct timeval start, struct timeval end){
	int elapsed_seconds = 0;
	double elapsed_useconds = 0.0, aux = 0.0;
	
	/* elapsed_seconds represents the difference, in seconds, between the whole elapsed time and the time when the execution began */
	elapsed_seconds = end.tv_sec - start.tv_sec;

	/* elapsed_useconds contains the rest of the whole elapsed time (a fraction of a second), represented as the number of microseconds */
	elapsed_useconds = end.tv_usec - start.tv_usec;
	
	
	if(elapsed_useconds < 0){
		elapsed_useconds = end.tv_usec + (1000000 - start.tv_usec);
		elapsed_seconds--;
	}
	                                
	aux = elapsed_useconds/1000000;
	aux = elapsed_seconds + aux;
	                                
	return(aux);
}
